const express = require("express");
const router = express.Router();
const articlesCtrl = require("../controller/article");
const auth = require("../middleware/auth");
const articleValidator = require("../validator/article");

// 创建文章
router.post(
  "/",
  auth,
  articleValidator.createArticle,
  articlesCtrl.createArticle
);

// 获取文章
router.get("/:articleId", articleValidator.getArticle, articlesCtrl.getArticle);

// 获取文章列表
router.get("/", articlesCtrl.getArticles);

// 更新文章
router.put(
  "/:articleId",
  auth,
  articleValidator.updateArticle,
  articlesCtrl.updateArticle
);

// 删除文章
router.delete(
  "/:articleId",
  auth,
  articleValidator.deleteArticle,
  articlesCtrl.deleteArticle
);

// 获取用户关注的作者文章列表
router.get("/feed", articlesCtrl.getFeedArticles);

// 添加文章评论
router.post("/:articleId/comments", articlesCtrl.createArticleComment);

// 获取文章评论列表
router.get("/:articleId/comments", articlesCtrl.getArticleComments);

// 删除文章评论
router.delete("/:articleId/comments/:id", articlesCtrl.deleteArticleComment);

module.exports = router;
